package com.zjt.web.api;

import com.zjt.service.user.IClientUserService;
import com.zjt.service.user.IFeedBackService;
import com.zjt.web.api.vo.base.StateVO;
import com.zjt.web.api.vo.request.FeedbackReqVO;
import com.zjt.web.api.vo.response.FeedbackRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by IntelliJ IDEA.
 * User: xueyanbeijing
 * Date: 12-8-14
 * Time: AM10:51
 * 反馈接口
 */

@Controller
@RequestMapping(value = "/api/feedback")
public class FeedbackAPIController {
    private static Logger logger = LoggerFactory.getLogger(FeedbackAPIController.class);
    private IFeedBackService feedBackService;
    private IClientUserService clientUserService;
    @Autowired
    public void setFeedBackService(IFeedBackService feedBackService) {
        this.feedBackService = feedBackService;
    }
    @Autowired
    public void setClientUserService(IClientUserService clientUserService) {
        this.clientUserService = clientUserService;
    }

    /**
     * 反馈
     *
     * @param feedbackReqVO
     * @return
     */
    @RequestMapping(value = {"add.json", ""})
    @ResponseBody
    public FeedbackRespVO add(FeedbackReqVO feedbackReqVO) {
        logger.info("/api/feedback/add request parms = " + feedbackReqVO.toString());
        //TODO 进行请求参数的解析
        StateVO stateVO = new StateVO();
        try
        {
            if (this.clientUserService.checkExistByUserId(feedbackReqVO.getUserId()))
                this.feedBackService.saveFeedBack(feedbackReqVO.getUserId(),feedbackReqVO.getEmail(),feedbackReqVO.getContent());
            else
            {
                stateVO.setCode(-1);
                stateVO.setMsg("client User Id 不存在");
                logger.error("client userId 不存在");
            }
        }catch (Exception e){}
        FeedbackRespVO feedbackRespVO = new FeedbackRespVO();
        //TODO 进行业务逻辑的处理 ， 封装应答数据
        feedbackRespVO.setStateVO(stateVO);
        logger.info("/api/feedback/add response result = " + feedbackRespVO.toString());
        return feedbackRespVO;
    }
}
